﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Net;
using System.Xml.Linq;

namespace mashArmory
{
    public class mshXML
    {
        /// <summary>
        ///  Gilden Daten auslesen
        /// </summary>
        /// <param name="guildName"></param>
        /// <param name="realm"></param>
        /// <returns></returns>
        public XDocument GetGuildData(string guildName, string realm)
        {
            // Creating URL for the Guild -> TODO: Sonderzeichen eventuell behandeln
            string editedGuildName = String.Empty;
            editedGuildName = guildName.Replace(' ', '+');
            string url = "http://eu.wowarmory.com/guild-info.xml?r=" + realm + "&n=" + editedGuildName;


            // WebClient mit user-agent definieren um XML statt HTML zu bekommen
            WebClient wc = new WebClient();
            wc.Headers.Add("User-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
            wc.Encoding = System.Text.Encoding.UTF8;
            string resultXML = wc.DownloadString(url);
            XDocument doc = XDocument.Parse(resultXML);
            return doc;
        }

    }
}
